เข้าสู่ระบบ สมัครสมาชิก

referentially transparent การใช้

ประโยคมือถือ
  • Therefore, function GetInput ( ) is neither deterministic nor referentially transparent.
  • Pure expressions are often referred to as being referentially transparent.
  • In fact, assignment statements are never referentially transparent.
  • In functional programming only referentially transparent functions are considered.
  • Arithmetic operations are referentially transparent : 5 * 5 can be replaced by 25, for instance.
  • The function that does this value-for-function-object replacement can generically wrap any referentially transparent function.
  • However, if the compiler is able to determine that the function call is referentially transparent, it can perform this transformation automatically.
  • As referential transparency requires the same results for any given set of inputs at any point in time, a referentially transparent expression is therefore deterministic.
  • If the substitution of an expression with its value is valid only at a certain point in the execution of the program, then the expression is not referentially transparent.
  • One advantage of writing code in a referentially transparent style is that given an intelligent compiler, static code analysis is easier and better code-improving transformations are possible automatically.
  • Clearly, replacing x = x * 10 with either 10 or 100 gives a program with different meaning, and so the expression " is not " referentially transparent.
  • In fact, all functions in the mathematical sense are referentially transparent : sin ( x ) is transparent, since it will always give the same result for each particular x.
  • However, because a referentially transparent expression can be evaluated at any time, it is not necessary to define sequence points nor any guarantee of the order of evaluation at all.
  • Programming languages often have richer semantics than logics'semantics of truth and falsity, and so an operator such as [ x ] may fail to be referentially transparent for other reasons as well.
  • While memoization may be added to functions " internally " and " explicitly " by a computer programmer in much the same way the above memoized version of factorial is implemented, referentially transparent functions may also be automatically memoized " externally " . and artificial intelligence.
  • This is then resolved according to name binding rules to a non-local variable, such as a global variable, a variable in the current execution environment ( for statically bound to a value, the function is still referentially transparent, as neither the non-local variable nor its value can change, due to static binding and immutability, respectively.
  • A function can only be memoized if it is referentially transparent; that is, only if calling the function has exactly the same effect as replacing that function call with its return value . ( Special case exceptions to this restriction exist, however . ) While related to lookup tables, since memoization often uses such tables in its implementation, memoization populates its cache of results transparently on the fly, as needed, rather than in advance.